<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.css">
  <link rel="stylesheet" href="/public/css/login.css">
</head>

<body>
  <div class="main">
    <div class="header">
      <a href="/">
        <img src="/public/img/开心果.png" alt="">
      </a>
      <h1>重置密码</h1>
    </div>
    
    <form id="reset_form" method="post" action="">
      <div class="form-group">
        <label for="">新的密码</label>
        <input type="password" class="form-control" placeholder="" name="npassword">
      </div>
      <div class="form-group">
        <label for="">确认密码</label>
        <input type="password" class="form-control" placeholder="" name="cpassword">
      </div>
      <div class="form-group" style="display: none;">
        <label for="">email</label>
        <input type="email" class="form-control" value="{{ email }}" name="email">
      </div>
      <button type="submit" class="btn btn-success btn-block">保存</button>
    </form>
    <div class="message">
      <p>已有账号? <a href="/login">点击登录</a>.</p>
    </div>
  </div>
  <script src="/node_modules/jquery/dist/jquery.js"></script>
  <script>
    $('#reset_form').on('submit', function (e) {
      e.preventDefault()
      var formData = $(this).serialize()
      $.ajax({
        url: '/savePassWord',
        type: 'post',
        data: formData,
        dataType: 'json',
        success: function (data) {
          console.log(data);
          if(data.err_code === 0) {
            alert('修改密码成功')
            location.href = '/login'
          }else {
            alert('新旧密码不一致')
            location.reload();
          }
        }
      })
    })
  </script>
</body>

</html>
